<template>
  <div class="venus-list-page">
    <!--中间付息查询界面-->
    <div class="page-search">
      <el-row type="flex" justify="space-between" class="page-list-head">
        <div class="title">中间付息信息查询</div>
      </el-row>
      <el-row type="flex" class="search-list">
        <el-row type="flex" class="list-items">
          <div class="venus-input-box">
            <label>产品组合</label>
            <el-select
              v-model="table.prodInterestPay_table.port_code"
              placeholder="请选择"
              @change="portfol_change_fnc">
              <el-option
                v-for="item in dict.t8_port_info_id"
                :key="item.value"
                :label="item.value + '-' + item.text"
                :value="item.value"
              />
            </el-select>
          </div>
          <div class="venus-input-box">
            <label>产品名称</label>
            <el-select v-model="table.prodInterestPay_table.prod_name" placeholder="请选择">
              <el-option
                v-for="item in dict.prod_code"
                :key="item.value"
                :label="item.value + '-' + item.text"
                :value="item.value"
              />
            </el-select>
          </div>
          <div class="venus-input-box">
            <label>成立日期</label>
            <el-date-picker
              v-model="table.prodInterestPay_table.interestpay_date_min"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入起始日期"
              value-format="yyyyMMdd"
            /> -
            <el-date-picker
              v-model="table.prodInterestPay_table.interestpay_date_max"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入截止日期"
              value-format="yyyyMMdd"
            />
          </div>
        </el-row>
        <!--      </el-row>-->
        <!--      <el-row type="flex" justify="end">-->

      </el-row>
      <el-row type="flex" class="list-items" justify="space-content">
        <div class="venus-btn-box">
          <el-button type="primary" @click="search">查询</el-button>
        </div>
        <div class="venus-btn-box">
          <el-button type="primary" @click="reset">重置</el-button>
        </div>
      </el-row>
    </div>
    <!--    查询列表返显-->
    <div class="page-list">
      <table-pagination
        :table-data="table.prodInterestPay_table.tableData"
        :table-header-config="table.tableHeaderConfig"
        highlight-current-row
        :total="table.prodInterestPay_table.total"
        :page-size="table.prodInterestPay_table.pageSize"
        :now-page="table.prodInterestPay_table.nowPage"
        :dict-data="dict"
        @current-change="currentChange"
        @table-current-change="get_search"
      />
    </div>
    <div class="page-list">

      <el-row type="flex" class="list-items" justify="space-content">
        <div class="venus-input-box">
          <label>付息日期</label>
          <el-date-picker
            v-model="table.prodInterestPay_table002.start_date"
            type="date"
            class="venus-input-middle venus-input-date"
            placeholder="请输入起始日期"
            value-format="yyyyMMdd"
          /> -
          <el-date-picker
            v-model="table.prodInterestPay_table002.end_date"
            type="date"
            class="venus-input-middle venus-input-date"
            placeholder="请输入截止日期"
            value-format="yyyyMMdd"
          />
        </div>
        <div class="venus-btn-box">
          <el-button type="primary" @click="search002">查询</el-button>
        </div>
      </el-row>
      <table-pagination
        :table-data="table.prodInterestPay_table002.tableData"
        :table-header-config="table.IntereTableHeaderConfig"
        highlight-current-row
        :total="table.prodInterestPay_table002.total"
        :page-size="table.prodInterestPay_table002.pageSize"
        :now-page="table.prodInterestPay_table002.nowPage"
        :operation-config="table.prodInterestPay_table002.operationConfig"
        :dict-data="dict"
        @current-change="currentChange002"
      />
    </div>
    <!--提前兑付弹出框-->
    <el-dialog :title="dialog.dlgTilte" :visible.sync="dialog.dlgFormVisible">
      <!-- ref=dlgForm用于验证表单 -->
      <el-form ref="dlgForm" :model="dialog.form" size="mini">
        <el-row>
          <el-col :xs="0" :sm="0" :md="0">
            <el-input v-model="dialog.form.t8_prod_info_id" :disabled="true" type="hidden" />
            <el-input v-model="dialog.form.t8_sys_portfol_id" :disabled="true" type="hidden" />
            <el-input v-model="dialog.form.change_date" :disabled="true" type="hidden" />
            <el-input v-model="dialog.form.intr_calsum" :disabled="true" type="hidden" />
            <el-input v-model="dialog.form.cust_rate" :disabled="true" type="hidden" />
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="产品组合代码"
              :label-width="dialog.dlgFormLabelWidth"
              prop="port_code"
            >
              <el-input v-model="dialog.form.port_code" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="产品代码"
              :label-width="dialog.dlgFormLabelWidth"
              prop="prod_code"
            >
              <el-input v-model="dialog.form.prod_code" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="产品类型"
              :label-width="dialog.dlgFormLabelWidth"
              prop="prod_mod"
            >
              <el-select
                v-model="dialog.form.prod_type"
                placeholder=""
                filterable
                clearable
                disabled
              >
                <el-option
                  v-for="(value,key,index) in dict.t8_no_structprod_type"
                  :key="index"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="产品名称"
              :label-width="dialog.dlgFormLabelWidth"
              prop="prod_name"
            >
              <el-input v-model="dialog.form.prod_name" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="产品模式"
              :label-width="dialog.dlgFormLabelWidth"
              prop="prod_mod"
            >
              <el-select
                v-model="dialog.form.prod_mod"
                placeholder="请选择产品模式"
                filterable
                clearable
                disabled
              >
                <el-option
                  v-for="(value,key,index) in dict.prod_mod"
                  :key="index"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="产品实际规模(元)"
              :label-width="dialog.dlgFormLabelWidth"
              prop="actual_scale"
            >
              <el-input v-model="dialog.form.actual_scale" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="核算方式"
              :label-width="dialog.dlgFormLabelWidth"
              prop="acct_mod"
            >
              <el-select
                v-model="dialog.form.acct_mod"
                placeholder="请选择核算方式"
                filterable
                clearable
                disabled
              >
                <el-option
                  v-for="(value,key,index) in dict.t8_busi_account_type"
                  :key="index"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="计息基础"
              :label-width="dialog.dlgFormLabelWidth"
              prop="basedays"
            >
              <el-input v-model="dialog.form.basedays" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="产品成立日"
              :label-width="dialog.dlgFormLabelWidth"
              prop="establish_date"
            >
              <el-date-picker
                v-model="dialog.form.establish_date"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="收益起始日"
              :label-width="dialog.dlgFormLabelWidth"
              prop="start_fee_date"
            >
              <el-date-picker
                v-model="dialog.form.start_fee_date"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="产品到期日"
              :label-width="dialog.dlgFormLabelWidth"
              prop="end_date"
            >
              <el-date-picker
                v-model="dialog.form.end_date"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="预期收益率(%)"
              :label-width="dialog.dlgFormLabelWidth"
              prop="expe_rate"
            >
              <el-input v-model="dialog.form.expe_rate" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="实际付息日"
              :label-width="dialog.dlgFormLabelWidth"
              prop="real_intrday"
              @change="obtainProfit"
            >
              <el-date-picker
                v-model="dialog.form.real_intrday"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd"
                @change="obtainProfit"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="客户收益(元)"
              :label-width="dialog.dlgFormLabelWidth"
              prop="expe_rate"
              :rules="dialog.formRules.expe_rate"
            >
              <el-input v-model="dialog.form.convert_income" type="number" @change="moneyToChange"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="客户实际收益率(%)"
              :label-width="dialog.dlgFormLabelWidth"
              prop="real_rate"
              :rules="dialog.formRules.real_rate"
            >
              <el-input v-model="dialog.form.real_rate" type="number" @change="changeToMoney"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div v-show="!dialog.zjfx" slot="footer" class="dialog-footer" style="text-align: center">
      <el-button type="success" @click="zjfxOk">确 定</el-button>
      <el-button type="info" plain @click="dialog.dlgFormVisible=false">取 消</el-button>
      </div>
      <div v-show="!dialog.zjfxqr" slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="success" @click="zjfxqrOk">确 定</el-button>
        <el-button type="info" plain @click="dialog.dlgFormVisible=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as kk from '../../../../../utils/k-utils'
  import request from '../../../../../utils/request'

  export default {
    name: 'ProdInterestPay',
    data() { // 数据定义
      return {
        // 数据字典
        dict: {
          trans_stat: {},
          prod_mod: {},
          t8_no_structprod_type: {},
          t8_busi_account_type: {},
          t8_port_info_id: [],
          prod_code: []
        },
        // 表格
        table: {
          tableHeaderConfig: [ // 表头配置
            { prop: 'port_name', label: '产品组合名称' },
            { prop: 'prod_mod', label: '产品模式' },
            { prop: 'prod_code', label: '产品代码' },
            { prop: 'prod_name', label: '产品名称' },
            { prop: 'establish_date', label: '产品成立日' },
            { prop: 'end_date', label: '产品到期日' },
            { prop: 'prod_period', label: '产品期限(天)' },
            { prop: 'expe_rate', label: '预期收益率(%)' }
          ],
          IntereTableHeaderConfig: [ // 表头配置
            { prop: 'prod_code', label: '产品代码' },
            { prop: 'pre_intrday', label: '本次付息起始日期' },
            { prop: 'change_date', label: '本次付息截止日期' },
            { prop: 'real_intrday', label: '实际付息日' },
            { prop: 'intr_calsum', label: '计息天数' },
            { prop: 'change_date', label: '付息日期' },
            { prop: 'actual_scale', label: '产品实际规模' },
            { prop: 'trans_stat', label: '是否已确认' }
          ],
          prodInterestPay_table: {
            limit: 5, // 分页配置
            total: 0, // 数据总条数
            nowPage: 1, // 当前页
            tableData: [], // 表格数据
            exeid: 'prodInterestPayES_003', // exeid
            // 以下是查询参数
            port_code: '',
            prod_name: '',
            interestpay_date_min: '',
            interestpay_date_max: ''
          },
          prodInterestPay_table002: {
            limit: 5, // 分页配置
            total: 0, // 数据总条数
            nowPage: 1, // 当前页
            tableData: [], // 表格数据
            exeid: 'prodInterestPayES_004', // exeid
            operationConfig: { // 表格操作配置
              fixed: 'left',
              width: 200,
              operationButton: [
                // value:操作文字； func:回调函数
                { value: '中间付息', func: this.prodinterestpayA001 },
                { value: '中间付息确认', func: this.prodinterestpayS001 }
              ]
            },
            // 以下是查询参数
            prod_code: '',
            start_date: '',
            end_date: ''
          }
        },
        dialog: {
          dlgTilte: '标题',
          dlgFormVisible: false,
          dlgFormDisabled: true,
          zjfx: false, // 中间付息显示
          zjfxqr: false, // 中间付息确认显示
          dlgFormLabelWidth: '160px',
          formRules: {
            port_code: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            prod_code: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            prod_name: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            prod_mod: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            actual_scale: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            acct_mod: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            basedays: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            establish_date: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            start_fee_date: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            end_date: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            expe_rate: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            real_intrday: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            convert_income: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            real_rate: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ],
            intr_calsum: [
              { required: true, message: '该项不能为空', trigger: 'blur' }
            ]
          },
          form: {
            t8_prod_info_id: '', // 产品id
            t8_sys_portfol_id: '', // 产品组合ID
            change_date: '', // 付息日期
            port_code: '', // 产品组合代码
            prod_code: '', // 产品代码
            prod_type: '', // 产品类型
            prod_name: '', // 产品名称
            prod_mod: '', // 产品模式
            actual_scale: '', // 产品实际规模(元)
            acct_mod: '', // 核算方式
            basedays: '', // 计息基础
            establish_date: '', // 产品成立日
            start_fee_date: '', // 收益起始日
            end_date: '', // 产品到期日
            expe_rate: '', // 预期收益率(%)
            real_intrday: '', // 实际付息日
            cust_rate: '', // 客户预期收益率(%)
            convert_income: '', // 客户收益(元)
            real_rate: '', // 客户实际收益率(%)
            intr_calsum: '' // 计息天数
          }
        }
      }
    },
    mounted() {
      // 初始化调用
      this.init()
    },
    methods: {
      init: function() {
        kk.k_load_dict(this, 'trans_stat', '1yes0no')
        kk.k_load_dict(this, 'prod_mod', 't8_prod_model')
        kk.k_load_dict(this, 't8_no_structprod_type', 't8_no_structprod_type')
        kk.k_load_dict(this, 't8_busi_account_type', 't8_busi_account_type')
        this.load_dict_exeid(this, 'prod', 'prodInterestPayES_001', 't8_port_info_id')
        this.load_dict_exeid(this, 'prod', 'prodInterestPayES_002', 'prod_code')
        this.table.prodInterestPay_table.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'prodInterestPay_table', 'prod')
      },
      portfol_change_fnc(val) { // 选择了产品组合之后加载产品信息
        this.load_dict_exeid_byParams(this, 'prod', { t8_sys_portfol_id: val }, 'prodInterestPayES_002', 'prod_code')
      },
      search() { // 查询函数
        this.table.prodInterestPay_table.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'prodInterestPay_table', 'prod')
        // 清空联动表
        this.table.prodInterestPay_table002.tableData = ''
      },
      search002() { // 列表2查询函数
        this.table.prodInterestPay_table002.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'prodInterestPay_table002', 'prod')
      },
      reset() { // 重置函数
        this.table.prodInterestPay_table.prod_name = ''
        this.table.prodInterestPay_table.port_code = ''
        this.table.prodInterestPay_table.interestpay_date_min = ''
        this.table.prodInterestPay_table.interestpay_date_max = ''
        this.load_dict_exeid(this, 'prod', 'prodInterestPayES_002', 'prod_code')
      },
      prodinterestpayA001(params) { // 中间付息函数
        this.dialog.dlgTilte = '中间付息'
        this.dialog.zjfx = false // 显示中间付息按钮
        this.dialog.zjfxqr = true // 隐藏中间付息确认按钮
        this.copyObj(params, this.dialog.form)
        this.dialog.dlgFormVisible = true
      },
      prodinterestpayS001(params) { // 中间付息确认函数
        this.dialog.dlgTilte = '中间付息确认'
        this.dialog.zjfx = true // 隐藏中间付息按钮
        this.dialog.zjfxqr = false // 显示中间付息确认按钮
        this.copyObj(params, this.dialog.form)
        this.dialog.dlgFormVisible = true
      },
      // 中间付息提交
      zjfxOk() {
        // 获取全局对象数据
        var bean = this.dialog.form
        var _this = this
        this.send_save('prod', 'prodInterestPayEI_001', bean).then(rep => {
          _this.search()
          // 关闭弹出框
          _this.dialog.dlgFormVisible = false
        })
      },
      // 中间付息确认提交
      zjfxqrOk() {
        // 获取全局对象数据
        var bean = this.dialog.form
        var _this = this
        this.send_save('prod', 'prodInterestPayEU_001', bean).then(rep => {
          _this.search()
          // 关闭弹出框
          _this.dialog.dlgFormVisible = false
        })
      },
      // 发送保存
      send_save(service_name, exeid, params) {
        params.exeid = exeid
        return request({
          loading: true,
          url: service_name + '/base/comn-update.json',
          method: 'post',
          params: params
        })
      },
      // 下一页触发的事件
      currentChange(index) {
        this.table.prodInterestPay_table.nowPage = index
        kk.k_load_table(this, 'prodInterestPay_table', 'prod')
      },
      currentChange002(index) {
        this.table.prodInterestPay_table002.nowPage = index
        kk.k_load_table(this, 'prodInterestPay_table002', 'prod')
      },
      // 列表联动
      get_search(params) {
        this.table.prodInterestPay_table002.nowPage = 1 // 初始第一页
        this.table.prodInterestPay_table002.prod_code = params.prod_code // 查询该产品的销售区域字段
        kk.k_load_table(this, 'prodInterestPay_table002', 'prod')
      },
      moneyToChange() {
        // 产品模式
        var prod_mod = this.dialog.form.prod_mod
        if (prod_mod != 2) {
          return false
        }
        // 实际规模
        var actual_scale = this.dialog.form.actual_scale
        // 计息天数
        var intr_calsum = this.dialog.form.intr_calsum
        // 计息基础
        var rate_base = this.dialog.form.basedays
        // 客户收益
        var cust_income = this.dialog.form.convert_income
        // 客户实际收益率
        var real_rate = 0
        // 客户实际收益率=(客户收益*计息基础*100/实际规模/计息天数)
        real_rate = (cust_income * rate_base * 100 / actual_scale / intr_calsum).toFixed(4)
        this.dialog.form.real_rate = real_rate
      },
      // 客户实际收益率联动收益金额
      changeToMoney() {
        // 产品模式
        if (this.dialog.form.prod_mod != 2) {
          return false
        }
        var cust_income = this.calCustIncome() // 计算客户收益
        if (cust_income) {
          cust_income = parseFloat(cust_income).toFixed(3);
          cust_income = parseFloat(cust_income.toString().substr(0, cust_income.toString().indexOf('.') + 3))
        }
        // 页面上客户收益字段为:convert_income
        this.dialog.form.convert_income = cust_income
      },
      calCustIncome() {
        // 实际规模
        var actual_scale = this.dialog.form.actual_scale
        // 客户实际收益率
        var real_rate = this.dialog.form.real_rate ? this.dialog.form.real_rate : this.dialog.form.expe_rate
        // 计息天数
        var intr_calsum = this.dialog.form.intr_calsum
        // 计息基础 默认：365
        var basedays = this.dialog.form.basedays
        if (!basedays) {
          basedays = 365
        }
        // 客户收益
        var cust_income = 0

        // 客户收益=实际规模*客户收益率*计息天数/计息基础/100
        cust_income = actual_scale * real_rate * intr_calsum / basedays / 100
        if (cust_income) {
          cust_income = parseFloat(cust_income).toFixed(3)
          cust_income = parseFloat(cust_income.toString().substr(0, cust_income.toString().indexOf('.') + 3))
        }
        return cust_income
      },
      /* 通过exeid加载字典 */
      load_dict_exeid(this_object, service_name, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post'
        }).then(rep => {
          this_object['dict'][dict] = rep.rows
        })
      },
      /* 通过exeid加载字典 */
      load_dict_exeid_byParams(this_object, service_name, params, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post',
          params: params
        }).then(rep => {
          this_object['dict'][dict] = rep.rows
        })
      },
      /*
       * 将obj1对象的数据拷贝到obj对象
       */
      copyObj(obj1, obj2) {
        for (var key in obj1) {
          if (key === '__proto__') {
            continue
          }
          obj2[key] = obj1[key]
        }
      }
    }
  }
</script>

<style scoped>
</style>
